﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TTDataAccess;
using TTEntity;
using System.Data;

namespace TTBusiness
{
    public class clsBSTypeProduct
    {
        clsDATypeProduct objDA = new clsDATypeProduct();
        private clsTypeProduct getDataFromRow(DataRow dr)
        {
            try
            {
                clsTypeProduct obj = new clsTypeProduct();
                if (!dr.Equals(null))
                {
                    if (!dr.IsNull("ID"))
                        obj.Id = Convert.ToInt32(dr["ID"]);
                    if (!dr.IsNull("Detail"))
                        obj.Detail = dr["Detail"].ToString();
                    if (!dr.IsNull("Image"))
                        obj.Image = dr["Image"].ToString();
                    if (!dr.IsNull("Name"))
                        obj.Name = dr["Name"].ToString();
                    if (!dr.IsNull("Number"))
                        obj.Number = Convert.ToInt32(dr["Number"]);
                    if (!dr.IsNull("Visible"))
                        obj.Visible = Convert.ToBoolean(dr["Visible"]);
                    if (!dr.IsNull("Status"))
                        obj.Status = Convert.ToBoolean(dr["Status"]);
                }
                return obj;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public List<clsTypeProduct> getAll()
        {
            try
            {

                List<clsTypeProduct> objList = new List<clsTypeProduct>();
                DataTable dt = new DataTable();
                dt = objDA.GetAll();
                foreach (DataRow dr in dt.Rows)
                {
                    clsTypeProduct account = new clsTypeProduct();
                    account = getDataFromRow(dr);
                    objList.Add(account);
                }
                return objList;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Insert(clsTypeProduct obj)
        {
            try
            {
                objDA.Insert(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Update(clsTypeProduct obj)
        {
            try
            {
                objDA.Update(obj);
            }
            catch (Exception)
            {

                throw;
            }
        }
        public void Delete(int id)
        {
            try
            {
                objDA.Delete(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
